﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WarningAndMonitingSystem.Controls
{
    public partial class UPump : UserControl
    {
        public UPump()
        {
            InitializeComponent();
            stateBtn.Click += StateBtn_Click;
        }

        public event EventHandler StateChanged;

        private void StateBtn_Click(object? sender, EventArgs e)
        {
            StateChanged?.Invoke(this, EventArgs.Empty);
        }

        private bool isOn = false;
        [Category("自定义属性")]
        [Description("是否启动")]
        public bool IsOn
        {
            get { return isOn; }
            set
            {
                isOn = value;

                if (isOn)
                {
                    State = "ON";
                    LightImg = Properties.Resources.light_on;
                }
                else
                {
                    State = "OFF";
                    LightImg = Properties.Resources.light_off;
                }
            }
        }

        private Bitmap lightImg = Properties.Resources.light_off;
        [Category("自定义属性")]
        [Description("指示灯图片")]
        public Bitmap LightImg
        {
            get { return lightImg; }
            set
            {
                lightImg = value;
                picBox.Image = lightImg;
            }
        }


        private string state = "OFF";
        [Category("自定义属性")]
        [Description("水泵启停状态")]
        public string State
        {
            get { return state; }
            set
            {
                state = value;
                if (state == "OFF")
                {
                    stateBtn.BackColor = Color.Orange;
                }
                else
                {
                    stateBtn.BackColor = Color.LimeGreen;
                }
                stateBtn.Text = state;
            }
        }

        private string deviceName = "1#水泵";
        [Category("自定义属性")]
        [Description("设备名称")]
        public string DeviceName
        {
            get { return deviceName; }
            set
            {
                deviceName = value;
                deviceLb.Text = $"设备名称: {deviceName}";
            }
        }

        private string stateParamName;
        [Category("自定义属性")]
        [Description("状态参数名称")]
        public string StateParamName
        {
            get { return stateParamName; }
            set
            {
                stateParamName = value;
            }
        }

        private string frequencyParamName;
        [Category("自定义属性")]
        [Description("频率参数名称")]
        public string FrequencyParamName
        {
            get { return frequencyParamName; }
            set
            {
                frequencyParamName = value;
            }
        }

        private string powerParamName;
        [Category("自定义属性")]
        [Description("频率参数名称")]
        public string PowerParamName
        {
            get { return powerParamName; }
            set
            {
                powerParamName = value;
            }
        }

        private int frequency = 0;
        [Category("自定义属性")]
        [Description("频率")]
        public int Frequency
        {
            get { return frequency; }
            set
            {
                frequency = value;
                freqTxt.TValue = $"{frequency}";
            }
        }


        private int power = 0;
        [Category("自定义属性")]
        [Description("功率")]
        public int Power
        {
            get { return power; }
            set
            {
                power = value;
                powerTxt.TValue = $"{power}";
            }
        }

        private bool freqAlarmOn = false;
        [Category("自定义属性")]
        [Description("频率灯泡是否启动")]
        public bool FreqAlarmOn
        {
            get { return freqAlarmOn; }
            set
            {
                freqAlarmOn = value;
                uAlarm1.IsOn = freqAlarmOn;
            }
        }

        private Color[] freqAlarmColors = { Color.Red, Color.Pink };
        [Category("自定义属性")]
        [Description("频率灯泡颜色")]
        public Color[] FreqAlarmColors
        {
            get { return freqAlarmColors; }
            set
            {
                freqAlarmColors = value;
                uAlarm1.LightColors = freqAlarmColors;
            }
        }


        private bool powerAlarmOn = false;
        [Category("自定义属性")]
        [Description("功率灯泡是否启动")]
        public bool PowerAlarmOn
        {
            get { return powerAlarmOn; }
            set
            {
                powerAlarmOn = value;
                uAlarm2.IsOn = powerAlarmOn;
            }
        }

        private Color[] powerAlarmColors = { Color.Blue, Color.LightBlue };
        [Category("自定义属性")]
        [Description("功率灯泡颜色")]
        public Color[] PowerAlarmColors
        {
            get { return powerAlarmColors; }
            set
            {
                powerAlarmColors = value;
                uAlarm2.LightColors = powerAlarmColors;
            }
        }
    }
}
